/**
 * desc：
 * author：王文军
 * date：  2022/4/7 21:42
 */
"use strict";
const mongo = require("../utils/mongo");
module.exports = (app) => {
  class User extends app.Service {
    async say() {
      return "hello world";
    }

    async findUser(username) {
      return await mongo().find("user", { username });
    }

    async createUser(data) {
      const { ctx } = this;
      const { username, password } = data;
      // 密码加密
      const hash = await ctx.genHash(password);
      return await mongo().insert("user", [{ username, password: hash }]);
    }
  }

  return User;
};
